<template lang="pug">
    div#home
        img(:src='homeInfo.imgurl', width='100%')
        balance(v-if="homeInfo.amount",:balance="homeInfo.balance",:amount="homeInfo.amount")
        div
          oppointment(v-for="order in homeInfo.orders",:key="order.oid",:order="order", @cancel="cancelOrder")
        item-list(:items="homeInfo.items",title="项目")
        item-list(:products="homeInfo.products",title="产品")
</template>
<script>
import Balance from "../components/Balance.vue";
import Oppointment from "../components/Oppointment.vue";
import ItemList from "../components/ItemList.vue";
import _ from "lodash";
import { mapMutations } from 'vuex';

export default {
  components: {
    Balance,
    Oppointment,
    ItemList
  },
  data() {
    return {
      homeInfo: {}
    };
  },
  created() {
    this.getData();
  },
  methods: {
    ...mapMutations(['openEndTime']),
    getData() {
      this.$api.v1
        .home_homeInfo_post({ data: { uid: window.data.uid } })
        .then(resp => {
          this.homeInfo = resp.data;
          this.openEndTime(resp.data);
        });
    },
    cancelOrder() {
      this.getData();
    }
  }
};
</script>
<style lang="stylus" scoped>
.oppointment{
  border-bottom: solid 1px #ccc;
  &:last-child{
    border-bottom-color: transparent;
  }
}
</style>
